<?php session_start();
	ob_start();
	include("value.php");
	include("function.php");
	//=========== already isset cart
	$d=1;
	$masp=$_POST["masp"];
	$type=(!isset($_POST["type"])?"":$_POST['type']);
	$frequence=(!isset($_POST["frequence"])?"":$_POST['frequence']);
	$debutant=(!isset($_POST["debutant"])?"":$_POST['debutant']);
	
	switch($masp)
	{
		case "planter":  $price=$price_planter;break;
		case "trousse1": $price=$price_trousse1;break;
		case "trousse2": $price=$price_trousse2;break;
		case "trousse3": $price=$price_trousse3;break;
		case "trousse4": $price=$price_trousse4;break;
		case "don": 
			$price=($_POST['rdo']=="Autre")?$_POST['txt_price']:$_POST['rdo'];
			break;
		default: $price=0;break;
	}
	$qty=$_POST['txt_qty'];
	if(!check_number($qty) || ($_POST['masp']=="don" && $_POST['rdo']=="Autre" && (!is_numeric($_POST['txt_price']) || $_POST['txt_price']<=0)))
	{
		$error=($_POST['masp']=="planter")?"?error=1":"&error=1";
		header("refresh:0;url=".$_SERVER['HTTP_REFERER'].$error);
		return false;
	}
	if(isset($_SESSION["giohang"]))
	{
		foreach($_SESSION["giohang"] as $k=>$gt)
		{
			if($k==$_REQUEST["masp"])
			{
				$_SESSION["giohang"][$k][1]=$qty;
				$_SESSION["giohang"][$k][2]=$price;
				$_SESSION["giohang"][$k][3]=$type;
				$_SESSION["giohang"][$k][4]=$frequence;
				$_SESSION["giohang"][$k][5]=$debutant;
				$d=0;
				break;
			}
			//isset cart but not same masp
			else
				$d++;		
		}
	}
	//==========not isset cart
	if($d!=0)
	{
		$_SESSION["giohang"][$masp]=array($masp,$qty,$price,$type,$frequence,$debutant);
	}
	//print_r($_SESSION["giohang"]);
	header("refresh:0;url=/cart.html");
	
?>